import React from 'react';
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as Action from "../actions";
import { HashRouter as Router, Route, Link } from 'react-router-dom'


import Header from "../header.js"
import Form from "./order.js";
class Order extends React.Component {
    constructor(props) {
        super(props);
    }
    componentWillMount(){
        console.log(this.props.formList);
    }
    render() {
        
        document.title="订单详情";
        var countC = 0;
        const keepTwoDecimal = (num) => {
            var result = parseFloat(num);
            result = Math.round(num * 100) / 100;
            return result;
        }
        return <Router>
            <div>
                <Header />
                <Form forminfo={this.props.formList} createTime={this.props.createTime} orderId={this.props.orderId} />
                <footer>
                    <div className="price">
                        <a>共计</a>
                        {
                            this.props.formList.forEach((item) => {
                                let priceC = 0;
                                priceC = item.productQuantity * item.productPrice;
                                countC += priceC;
                            })
                        }
                        <span>￥{keepTwoDecimal(countC)}</span>
                    </div>
                    <div className="shopBtn">
                        <Link to="/product">加单</Link>
                    </div>
                </footer>
            </div>
        </Router>
    }
}
export default connect(
    ({ orderReducer }) => {
        return {
            formList: orderReducer.order,
            createTime: orderReducer.createTime,
            orderId: orderReducer.orderId
        }
    }
)(Order)